package com.integration.pojo;

import java.math.BigInteger;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.json.JSONException;
import org.json.JSONObject;

public class TwittMessage {
	private static final String DATE_PATTERN = "EEE MMM dd HH:mm:ss ZZZZ yyyy"; //Ex.: Fri Jun 15 07:54:32 +0000 2012
	private String in_reply_to_status_id_str;
	private Boolean retweeted;
	private Date created_at;
	private String in_reply_to_user_id_str;
	private String coordinates;
	private String geo;
	private String in_reply_to_screen_name;
	private String contributors;
	private TwittUserInfo user;
	private BigInteger retweet_count;
	private Boolean favorited;
	private String id_str;
	private String in_reply_to_status_id;
	private Boolean truncated;
	private String source;
	private String place;
	private BigInteger id;
	private BigInteger in_reply_to_user_id;
	private String text;
	
	public TwittMessage(JSONObject in) throws JSONException, ParseException {
		super();
		this.in_reply_to_status_id_str = in.optString("in_reply_to_status_id_str");
		this.retweeted = in.optBoolean("retweeted");
		this.created_at = (new SimpleDateFormat(DATE_PATTERN, Locale.US)).parse(in.optString("created_at"));
		this.in_reply_to_user_id_str = in.optString("in_reply_to_user_id_str"); 
		this.coordinates = in.optString("coordinates");
		this.geo = in.optString("geo");
		this.in_reply_to_screen_name = in.optString("in_reply_to_screen_name");
		this.contributors = in.optString("contributors");
		this.user = new TwittUserInfo(in.optJSONObject("user"));
		this.retweet_count = BigInteger.valueOf(in.optLong("retweet_count"));
		this.favorited = in.optBoolean("favorited");
		this.id_str = in.optString("id_str");
		this.in_reply_to_status_id = in.optString("in_reply_to_status_id");
		this.truncated = in.optBoolean("truncated");
		this.source = in.optString("source");
		this.place = in.optString("place");
		this.id = BigInteger.valueOf(in.optLong("id"));
		this.in_reply_to_user_id = BigInteger.valueOf(in.optLong("in_reply_to_user_id"));
		this.text = in.optString("text");
	}

	public String getIn_reply_to_status_id_str() {
		return in_reply_to_status_id_str;
	}
	public void setIn_reply_to_status_id_str(String in_reply_to_status_id_str) {
		this.in_reply_to_status_id_str = in_reply_to_status_id_str;
	}
	public Boolean getRetweeted() {
		return retweeted;
	}
	public void setRetweeted(Boolean retweeted) {
		this.retweeted = retweeted;
	}
	public Date getCreated_at() {
		return created_at;
	}
	public void setCreated_at(Date created_at) {
		this.created_at = created_at;
	}
	public String getIn_reply_to_user_id_str() {
		return in_reply_to_user_id_str;
	}
	public void setIn_reply_to_user_id_str(String in_reply_to_user_id_str) {
		this.in_reply_to_user_id_str = in_reply_to_user_id_str;
	}
	public String getCoordinates() {
		return coordinates;
	}
	public void setCoordinates(String coordinates) {
		this.coordinates = coordinates;
	}
	public String getGeo() {
		return geo;
	}
	public void setGeo(String geo) {
		this.geo = geo;
	}
	public String getIn_reply_to_screen_name() {
		return in_reply_to_screen_name;
	}
	public void setIn_reply_to_screen_name(String in_reply_to_screen_name) {
		this.in_reply_to_screen_name = in_reply_to_screen_name;
	}
	public String getContributors() {
		return contributors;
	}
	public void setContributors(String contributors) {
		this.contributors = contributors;
	}
	public TwittUserInfo getUser() {
		return user;
	}
	public void setUser(TwittUserInfo user) {
		this.user = user;
	}
	public BigInteger getRetweet_count() {
		return retweet_count;
	}
	public void setRetweet_count(BigInteger retweet_count) {
		this.retweet_count = retweet_count;
	}
	public Boolean getFavorited() {
		return favorited;
	}
	public void setFavorited(Boolean favorited) {
		this.favorited = favorited;
	}
	public String getId_str() {
		return id_str;
	}
	public void setId_str(String id_str) {
		this.id_str = id_str;
	}
	public String getIn_reply_to_status_id() {
		return in_reply_to_status_id;
	}
	public void setIn_reply_to_status_id(String in_reply_to_status_id) {
		this.in_reply_to_status_id = in_reply_to_status_id;
	}
	public Boolean getTruncated() {
		return truncated;
	}
	public void setTruncated(Boolean truncated) {
		this.truncated = truncated;
	}
	public String getSource() {
		return source;
	}
	public void setSource(String source) {
		this.source = source;
	}
	public String getPlace() {
		return place;
	}
	public void setPlace(String place) {
		this.place = place;
	}
	public BigInteger getId() {
		return id;
	}
	public void setId(BigInteger id) {
		this.id = id;
	}
	public BigInteger getIn_reply_to_user_id() {
		return in_reply_to_user_id;
	}
	public void setIn_reply_to_user_id(BigInteger in_reply_to_user_id) {
		this.in_reply_to_user_id = in_reply_to_user_id;
	}
	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((contributors == null) ? 0 : contributors.hashCode());
		result = prime * result
				+ ((coordinates == null) ? 0 : coordinates.hashCode());
		result = prime * result
				+ ((created_at == null) ? 0 : created_at.hashCode());
		result = prime * result
				+ ((favorited == null) ? 0 : favorited.hashCode());
		result = prime * result + ((geo == null) ? 0 : geo.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((id_str == null) ? 0 : id_str.hashCode());
		result = prime
				* result
				+ ((in_reply_to_screen_name == null) ? 0
						: in_reply_to_screen_name.hashCode());
		result = prime
				* result
				+ ((in_reply_to_status_id == null) ? 0 : in_reply_to_status_id
						.hashCode());
		result = prime
				* result
				+ ((in_reply_to_status_id_str == null) ? 0
						: in_reply_to_status_id_str.hashCode());
		result = prime
				* result
				+ ((in_reply_to_user_id == null) ? 0 : in_reply_to_user_id
						.hashCode());
		result = prime
				* result
				+ ((in_reply_to_user_id_str == null) ? 0
						: in_reply_to_user_id_str.hashCode());
		result = prime * result + ((place == null) ? 0 : place.hashCode());
		result = prime * result
				+ ((retweet_count == null) ? 0 : retweet_count.hashCode());
		result = prime * result
				+ ((retweeted == null) ? 0 : retweeted.hashCode());
		result = prime * result + ((source == null) ? 0 : source.hashCode());
		result = prime * result + ((text == null) ? 0 : text.hashCode());
		result = prime * result
				+ ((truncated == null) ? 0 : truncated.hashCode());
		result = prime * result + ((user == null) ? 0 : user.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TwittMessage other = (TwittMessage) obj;
		if (contributors == null) {
			if (other.contributors != null)
				return false;
		} else if (!contributors.equals(other.contributors))
			return false;
		if (coordinates == null) {
			if (other.coordinates != null)
				return false;
		} else if (!coordinates.equals(other.coordinates))
			return false;
		if (created_at == null) {
			if (other.created_at != null)
				return false;
		} else if (!created_at.equals(other.created_at))
			return false;
		if (favorited == null) {
			if (other.favorited != null)
				return false;
		} else if (!favorited.equals(other.favorited))
			return false;
		if (geo == null) {
			if (other.geo != null)
				return false;
		} else if (!geo.equals(other.geo))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (id_str == null) {
			if (other.id_str != null)
				return false;
		} else if (!id_str.equals(other.id_str))
			return false;
		if (in_reply_to_screen_name == null) {
			if (other.in_reply_to_screen_name != null)
				return false;
		} else if (!in_reply_to_screen_name
				.equals(other.in_reply_to_screen_name))
			return false;
		if (in_reply_to_status_id == null) {
			if (other.in_reply_to_status_id != null)
				return false;
		} else if (!in_reply_to_status_id.equals(other.in_reply_to_status_id))
			return false;
		if (in_reply_to_status_id_str == null) {
			if (other.in_reply_to_status_id_str != null)
				return false;
		} else if (!in_reply_to_status_id_str
				.equals(other.in_reply_to_status_id_str))
			return false;
		if (in_reply_to_user_id == null) {
			if (other.in_reply_to_user_id != null)
				return false;
		} else if (!in_reply_to_user_id.equals(other.in_reply_to_user_id))
			return false;
		if (in_reply_to_user_id_str == null) {
			if (other.in_reply_to_user_id_str != null)
				return false;
		} else if (!in_reply_to_user_id_str
				.equals(other.in_reply_to_user_id_str))
			return false;
		if (place == null) {
			if (other.place != null)
				return false;
		} else if (!place.equals(other.place))
			return false;
		if (retweet_count == null) {
			if (other.retweet_count != null)
				return false;
		} else if (!retweet_count.equals(other.retweet_count))
			return false;
		if (retweeted == null) {
			if (other.retweeted != null)
				return false;
		} else if (!retweeted.equals(other.retweeted))
			return false;
		if (source == null) {
			if (other.source != null)
				return false;
		} else if (!source.equals(other.source))
			return false;
		if (text == null) {
			if (other.text != null)
				return false;
		} else if (!text.equals(other.text))
			return false;
		if (truncated == null) {
			if (other.truncated != null)
				return false;
		} else if (!truncated.equals(other.truncated))
			return false;
		if (user == null) {
			if (other.user != null)
				return false;
		} else if (!user.equals(other.user))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "TwittMessage [in_reply_to_status_id_str="
				+ in_reply_to_status_id_str + ", retweeted=" + retweeted
				+ ", created_at=" + created_at + ", in_reply_to_user_id_str="
				+ in_reply_to_user_id_str + ", coordinates=" + coordinates
				+ ", geo=" + geo + ", in_reply_to_screen_name="
				+ in_reply_to_screen_name + ", contributors=" + contributors
				+ ", user=" + user + ", retweet_count=" + retweet_count
				+ ", favorited=" + favorited + ", id_str=" + id_str
				+ ", in_reply_to_status_id=" + in_reply_to_status_id
				+ ", truncated=" + truncated + ", source=" + source
				+ ", place=" + place + ", id=" + id + ", in_reply_to_user_id="
				+ in_reply_to_user_id + ", text=" + text + "]";
	}
	
}
